package com.shaokel.eduservice.controller;

import com.shaokel.commonutils.ReturnResult;
import com.shaokel.eduservice.entity.subject.OneSubject;
import com.shaokel.eduservice.service.EduSubjectService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 课程科目 前端控制器
 *
 * @author 少丶客
 * @since 2020-06-02
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    //添加课程分类
    //获取上传过来的文件，把文件内容读取出来
    @PostMapping("/addSubject")
    public ReturnResult addSubject(MultipartFile file){
        //上传过来的excel文件
        eduSubjectService.savaSubject(file,eduSubjectService);
        return ReturnResult.ok();
    }

    //课程分类列表（树形）
    @GetMapping("/getAllSubject")
    public ReturnResult getAllSubject(){
        //list集合中的泛型是一级分类，一级分类中包含二级分类
        List<OneSubject> list = eduSubjectService.getAllOneTwoSubject();
        return ReturnResult.ok().data("list",list);
    }

}

